package com.bjmashibing.system.huawei;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Log 
{
    private final static Logger logger = LoggerFactory.getLogger(Log.class);
    private static final String TAG = "wyh";
    
    // ��־���ͱ�ʶ��(���ȼ����ɵ͵������У�ȡֵԽС���ȼ�Խ��)
    public static final char SHOW_VERBOSE_LOG = 0x01;
    public static final char SHOW_DEBUG_LOG   = 0x02;
    public static final char SHOW_INFO_LOG    = 0x04;
    public static final char SHOW_WARN_LOG    = 0x08;
    public static final char SHOW_ERROR_LOG   = 0x10;
    public static  File fileLogFilePath = null;
    public static  FileWriter     objFilerWriter = null;
    public static  BufferedWriter objBufferedWriter = null;
    public static  String str_file_name = "";
    // Ĭ��Ϊ������־���;��� LogCat �������ʾ
    public static char m_cLogCatShowLogType = SHOW_VERBOSE_LOG | 
                                              SHOW_DEBUG_LOG   | 
                                              SHOW_INFO_LOG    | 
                                              SHOW_WARN_LOG    | 
                                              SHOW_ERROR_LOG;
    // Ĭ��Ϊ������־���;��� ��־�ļ� ���������
    //public static char m_cFileSaveLogType = 1;
    // ����ע�Ͳ�Ҫɾ���Ա��պ���ָ����־�����������־�ļ���
    public static char m_cFileSaveLogType = SHOW_VERBOSE_LOG | 
                                            SHOW_DEBUG_LOG   | 
                                            SHOW_INFO_LOG    | 
                                            SHOW_WARN_LOG    | 
                                            SHOW_ERROR_LOG;
    
    

    // �����־�ļ���Ŀ¼ȫ·��
    public static String m_strLogFolderPath = "";

    private static void
    SaveLog2File( String strMsg )
    {
        
        /*do // 
        {
        	
            String strDateTimeLogHead = new SimpleDateFormat( "yyyy-MM-dd_HH:mm:ss" ).format( new Date() );
            strMsg = TAG + "SaveLog2File, " + strDateTimeLogHead + " " + strMsg + "\n\n";
            try 
            {
                objBufferedWriter.write( strMsg );
                objBufferedWriter.flush();
               
            } 
            catch (IOException e) 
            {
                android.util.Log.d( TAG, "objBufferedWriter.write or objBufferedWriter.flush failed" );
                e.printStackTrace();
            }            
            
        }while( false );*/

    }

    public static void 
    v( String msg ) 
    {
        // ���ַ��ȫ�ǿո���ַ���Ϊ��־���û�����壡
        if ( ( null == msg ) || 
             ( true == msg.trim().equals( "" ) ) )
        {
            return;
        }
        
        /*String strMsg = "\nfile: " + new Throwable().getStackTrace()[1].getFileName() +
                        " \nclass: " + new Throwable().getStackTrace()[1].getClassName() +
                        " \nmethod: " + new Throwable().getStackTrace()[1].getMethodName() +
                        " \nline: " + new Throwable().getStackTrace()[1].getLineNumber() + 
                        " \n" + msg + "\n\n";*/
        String strMsg =  msg;
        if ( 0 != ( SHOW_VERBOSE_LOG & 
                    m_cLogCatShowLogType ) )
        {
            //android.util.Log.v( TAG, strMsg );
        }

        if ( 0 != ( SHOW_VERBOSE_LOG & 
                    m_cFileSaveLogType ) )
        {
            SaveLog2File( strMsg );
        }
    }

    public static void 
    d( String msg ) 
    {
        // ���ַ��ȫ�ǿո���ַ���Ϊ��־���û�����壡
        if ( ( null == msg ) || 
             ( true == msg.trim().equals( "" ) ) )
        {
            return;
        }

       /* String strMsg = "\nfile: " + new Throwable().getStackTrace()[1].getFileName() +
                        " \nclass: " + new Throwable().getStackTrace()[1].getClassName() +
                        " \nmethod: " + new Throwable().getStackTrace()[1].getMethodName() +
                        " \nline: " + new Throwable().getStackTrace()[1].getLineNumber() + 
                        " \n" + msg;*/
        String strMsg =  msg;
        if ( 0 != ( SHOW_DEBUG_LOG & 
                    m_cLogCatShowLogType ) )
        {
            //android.util.Log.d( TAG, 
                                //strMsg );
        }
        
        if ( 0 != ( SHOW_DEBUG_LOG & 
                    m_cFileSaveLogType ) )
        {
            SaveLog2File( strMsg );
        }
    }

    public static void 
    i( String msg ) 
    {
        // ���ַ��ȫ�ǿո���ַ���Ϊ��־���û�����壡
        if ( ( null == msg ) || 
             ( true == msg.trim().equals( "" ) ) )
        {
            return;
        }

        /*String strMsg = "\nfile: " + new Throwable().getStackTrace()[1].getFileName() +
                        " \nclass: " + new Throwable().getStackTrace()[1].getClassName() +
                        " \nmethod: " + new Throwable().getStackTrace()[1].getMethodName() +
                        " \nline: " + new Throwable().getStackTrace()[1].getLineNumber() + 
                        " \n" + msg;*/
        String strMsg =  msg;
        
        if ( 0 != ( SHOW_INFO_LOG & 
                    m_cLogCatShowLogType ) )
        {
        	//android.util.Log.e( TAG, msg );
            //SaveLog2File( msg );
        }

        if ( 0 != ( SHOW_INFO_LOG & 
                    m_cFileSaveLogType ) )
        {
            logger.info( msg );

        }
    }

    public static void 
    w( String msg ) 
    {
        // ���ַ��ȫ�ǿո���ַ���Ϊ��־���û�����壡
        if ( ( null == msg ) || 
             ( true == msg.trim().equals( "" ) ) )
        {
            return;
        }

       /* String strMsg = "\nfile: " + new Throwable().getStackTrace()[1].getFileName() +
                        " \nclass: " + new Throwable().getStackTrace()[1].getClassName() +
                        " \nmethod: " + new Throwable().getStackTrace()[1].getMethodName() +
                        " \nline: " + new Throwable().getStackTrace()[1].getLineNumber() + 
                        " \n" + msg;*/
        String strMsg =  msg;
        if ( 0 != ( SHOW_WARN_LOG & 
                    m_cLogCatShowLogType ) )
        {
            //android.util.Log.w( TAG,  strMsg );
        }

        if ( 0 != ( SHOW_WARN_LOG & 
                    m_cFileSaveLogType ) )
        {
            SaveLog2File( strMsg );
        }
    }

    public static void 
    e( String msg ) 
    {
        // ���ַ��ȫ�ǿո���ַ���Ϊ��־���û�����壡
        if ( ( null == msg ) || 
             ( true == msg.trim().equals( "" ) ) )
        {
            return;
        }

       /* String strMsg = "\nfile: " + new Throwable().getStackTrace()[1].getFileName() +
                        " \nclass: " + new Throwable().getStackTrace()[1].getClassName() +
                        " \nmethod: " + new Throwable().getStackTrace()[1].getMethodName() +
                        " \nline: " + new Throwable().getStackTrace()[1].getLineNumber() + 
                        " \n" + msg;*/
        String strMsg =  msg;
        if ( 0 != ( SHOW_ERROR_LOG & 
                    m_cLogCatShowLogType ) )
        {
            //android.util.Log.e( TAG, msg );
        }
        
        if ( 0 != ( SHOW_ERROR_LOG & 
                    m_cFileSaveLogType ) )
        {
            SaveLog2File( strMsg );
        }
    }
}